
/*********************************************************************
 *
 *	Hardware specific definitions
 *
 *********************************************************************
 * FileName:        HardwareProfile.h
 * Dependencies:    None
 * Processor:       PIC24, dsPIC, PIC32
 * Compiler:        Microchip C30 and C32
 * Company:         Microchip Technology, Inc.
 *
 * Software License Agreement
 *
 * Copyright (c) 2011 Microchip Technology Inc.  All rights 
 * reserved.
 *
 * Microchip licenses to you the right to use, modify, copy, and 
 * distribute: 
 * (i)  the Software when embedded on a Microchip microcontroller or 
 *      digital signal controller product ("Device") which is 
 *      integrated into Licensee�s product; or
 * (ii) ONLY the Software driver source files ENC28J60.c and 
 *      ENC28J60.h ported to a non-Microchip device used in 
 *      conjunction with a Microchip ethernet controller for the 
 *      sole purpose of interfacing with the ethernet controller. 
 *
 * You should refer to the license agreement accompanying this 
 * Software for additional information regarding your rights and 
 * obligations.
 *
 * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT 
 * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT 
 * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A 
 * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL 
 * MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR 
 * CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF 
 * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS 
 * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE 
 * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER 
 * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT 
 * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE.
 *
 *
 * Date	                Comment
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * 10/03/06             Original, copied from Compiler.h
 * 06/25/09             dsPIC & PIC24H support 
 * 09/15/09             Added PIC24FJ256DA210 Development Board Support
 * 06/02/11             Added MPLAB X Support
 ********************************************************************/
#define SYS_FREQ (80000000L)
#define FCY     SYS_FREQ

#define GetSystemClock()    SYS_FREQ

// check is this is correct for a mx32 device xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
#define GetPeripheralClock()    SYS_FREQ/2

#define GetInstructionClock()   SYS_FREQ

// 4. Display Related Settings: These settings contain a set of #defines which defines the various display related parameters, such as the
// type of the display (TFT or CSTN or MSTN),resolution of the screen, color depth, display
// clock speed, various display timing parameters,address of the draw buffer and frame buffer among others.

#define GFX_LCD_TYPE GFX_LCD_TFT
        
        
#define DISP_HOR_RESOLUTION	 240
#define DISP_VER_RESOLUTION	 320

#define DISP_ORIENTATION    0
#define DISP_DATA_WIDTH     16

#define GFX_USE_DISPLAY_CONTROLLER_SSD1289
#define LCC_INTERNAL_MEMORY

//#define DISP_HOR_PULSE_WIDTH 25
//#define DISP_HOR_BACK_PORCH 5
//#define DISP_HOR_FRONT_PORCH 10
//#define DISP_VER_PULSE_WIDTH 4
//define DISP_VER_BACK_PORCH 0
//#define DISP_VER_FRONT_PORCH 2
// enable only signals that are needed by your display #define GFX_DISPLAYENABLE_ENABLE #define GFX_HSYNC_ENABLE #define GFX_VSYNC_ENABLE #define GFX_DISPLAYPOWER_ENABLE #define GFX_CLOCK_POLARITY GFX_ACTIVE_HIGH #define GFX_DISPLAYENABLE_POLARITY GFX_ACTIVE_HIGH #define GFX_HSYNC_POLARITY GFX_ACTIVE_LOW #define GFX_VSYNC_POLARITY GFX_ACTIVE_LOW #define GFX_DISPLAYPOWER_POLARITY GFX_ACTIVE_HIGH

// 5. Provide definitions of the I/O pins used in the application. These can be used as inputs for switches or outputs to turn on LEDs,
// or application controlled pins to enable specific hardware.

#define LED1_DIR    TRISGbits.TRISG12
#define LED2_DIR    TRISGbits.TRISG13
#define LED3_DIR    TRISGbits.TRISG14
#define LED4_DIR    TRISGbits.TRISG15

#define LED1        LATGbits.LATG12
#define LED2        LATGbits.LATG13
#define LED3        LATGbits.LATG14
#define LED4        LATGbits.LATG15

#define S1_DIR      TRISCbits.TRISC1
#define S2_DIR      TRISCbits.TRISC2
#define S3_DIR      TRISCbits.TRISC3

#define S1          PORTCbits.RC1
#define S2          PORTCbits.RC2
#define S3          PORTCbits.RC3

#define intialiseLeds() LED1_DIR = 0;LED2_DIR = 0;LED3_DIR = 0;LED4_DIR = 0;LED1 = 1;LED2 = 1;LED3 = 1;LED4 = 1;
#define intialiseSwitches() S1_DIR = 1;S2_DIR = 1;S3_DIR = 1;   // not entirely required as they are inputs by default on a PIC

// 6. External Memory Definitions: These #defines provide the definitions of port pins and/or module initialization, such as for SPI,
// I2C? or PMP to interface to the microcontroller with the external memory (EEPROM, Flash or SD Card).

#define USE_GFX_PMP
#define USE_16BIT_PMP

#define PMP_DATA_SETUP_TIME 10
#define PMP_DATA_WAIT_TIME 10
#define PMP_DATA_HOLD_TIME 10

#define LCD_RS          LATBbits.LATB15
#define LCD_RS_DIR      TRISBbits.TRISB15

#define LCD_CS          PORTDbits.RD11
#define LCD_CS_DIR      TRISDbits.TRISD11

#define LCD_WR          PORTDbits.RD4
#define LCD_WR_DIR      TRISDbits.TRISD4

#define LCD_RES         PORTBbits.RB14
#define LCD_RES_DIR     TRISBbits.TRISB14

#define LCD_BL         PORTDbits.RD1
#define LCD_BL_DIR     TRISDbits.TRISD1

#define TS_CS       PORTFbits.RF12
#define TS_CS_DIR   TRISFbits.TRISF12

//#define USE_SD_INTERFACE_WITH_SPI
//#define USE_USB_INTERFACE

//#define SPI_CHANNEL_4_ENABLE
//#define SPI_CHANNEL_3_ENABLE

#define SPI_FREQUENCY       (2000000)

// Secure Digital (SD) Card Chip Select
#define SD_CS		PORTDbits.RD14
#define SD_CS_TRIS	TRISDbits.TRISD14

// Secure Digital (SD) Card Detect
#define SD_CD		PORTEbits.RE9
#define SD_CD_TRIS	TRISEbits.TRISE9

// Secure Digital (SD) Write Enable
// We don't have a Write Enable I/O pin on the uSD card.
// Hardcode WE to 1 (enable)
#define SD_WE   1
#define SD_WE_TRIS      TRISEbits.TRISE9

// Use SPI3 - Map Registers
#define SPICON1         SPI3CON
#define SPISTAT		SPI3STAT
#define SPIBUF		SPI3BUF
#define SPISTAT_RBF	SPI3STATbits.SPIRBF
#define SPICON1bits	SPI3CONbits
#define SPISTATbits	SPI3STATbits
#define SPIENABLE       SPI3CONbits.ON
#define SPIBRG          SPI3BRG

// Map SPI3 direction pins
#define SPICLOCK	TRISDbits.TRISD15
#define SPIIN           TRISFbits.TRISF8
#define SPIOUT		TRISFbits.TRISF2

// Map SPI3 peripheral library functions.
// The legacy putcSPI()/getcSPI()/OpenSPI1() functions do not exist for
// SPI3 and SPI4, hence we use the SpiChannelXX functions.
#define putcSPI(data_out)   SpiChnPutC(3,data_out)
#define getcSPI()           SpiChnGetC(3)

#define SPI_START_CFG_1     (SPI_OPEN_MSTEN | SPI_OPEN_CKE_REV | SPI_OPEN_SMP_END)
#define SPI_START_CFG_2     (80000000/SPI_FREQUENCY)

#define OpenSPI(oFlags, srcClkDiv)  SpiChnOpen(3, oFlags, srcClkDiv)


// 7. Touch Screen Definitions: These #defines provide the definitions and setup information of ADC channels used for sensing a touch in touch
// screen-enabled applications.


// 8. RTCC Definitions: These #defines provide setup information for the RTCC module if an internal Real-Time Clock (RTC) is used in the application.

// 9. Communication Definitions: These #defines provide the definitions and setup information of communication modules, such as
// UART/USB channels used for communication proposes in the application.


// 10. Application-Specific Definitions: Any other application-specific hardware definitions can be included here.


#include "SSD1289.h"
   
